package com.arcsoft.commonbase.widgets.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import android.widget.TextView
import com.arcsoft.commonbase.R
import com.arcsoft.commonbase.ext.gone


class CommonDialog(
    context: Context,
    var title: String? = null,
    var desc: String? = null,
    var sureCallback: () -> Unit
) :
    Dialog(context, R.style.CommonDialog) {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.dialog_sure_cancel)
        setCanceledOnTouchOutside(false)
        //设置黑暗度
        window?.apply {
            attributes.dimAmount = 0.3f
            addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
        }
        val tv_title = findViewById<TextView>(R.id.tv_title)
        val tv_desc = findViewById<TextView>(R.id.tv_desc)

        title?.apply { tv_title.text = this }
        desc?.apply { tv_desc.text = this }
        if (desc.isNullOrEmpty()) {
            tv_desc.gone()
        }

        findViewById<View>(R.id.btn_sure).setOnClickListener {
            dismiss()
            sureCallback.invoke()
        }
        findViewById<View>(R.id.btnCancel).setOnClickListener {
            dismiss()
        }
    }


}



